package com.sx.cms.biz.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sx.cms.biz.IUserInfoBiz;
import com.sx.cms.dao.IUserInfoDao;
import com.sx.cms.entity.UserInfoEntity;
import com.sx.feesunit.exception.SXException;

public class UserInfoBiz implements IUserInfoBiz {
	private IUserInfoDao userinfodao;
	private Log log = LogFactory.getLog(this.getClass());
	
	/* (non-Javadoc)
	 * @see com.sx.cms.biz.IUserInfoBiz#getUserInfo(com.sx.cms.entity.UserInfoEntity)
	 */
	public UserInfoEntity getUserInfo(UserInfoEntity userinfo)
			throws SXException {
		UserInfoEntity user = null;
		try {
			user = userinfodao.getUserInfoForLogin(userinfo);
		} catch (Exception e) {
			log.error("获取数据信息",e);
		}
		return user;
	}
	/**
	 * 检查用户登录名是否存在
	 **/
	public boolean checkLoginNameIsAvliable(UserInfoEntity userinfo) throws SXException{
		boolean flag = true;
		try {
			
			UserInfoEntity user = userinfodao.findUserInfoEntity(userinfo);
			if(user!=null){
				flag = false;
			}
		} catch (Exception e) {
			log.error("检查用户邮箱是否存在",e);
		}
		return flag;
	}
	public Integer addUserInfo(UserInfoEntity userinfo) throws SXException {
		// TODO Auto-generated method stub
		Integer id = null;
		try {
			id = userinfodao.addUserInfo(userinfo);
		} catch (Exception e) {
			// TODO: handle exception
			log.error("新增用户信息",e);
			throw new SXException(e);
		}
		return id;
	}

	public boolean editUserInfo(UserInfoEntity userinfo) throws SXException {
		boolean flag = false;
		try {
			flag = userinfodao.editUserInfo(userinfo);
		} catch (Exception e) {
			// TODO: handle exception
			log.error("编辑用户信息",e);
			throw new SXException(e);
		}
		return flag;
	}
	/**
	 * @return the userinfodao
	 */
	public IUserInfoDao getUserinfodao() {
		return userinfodao;
	}
	/**
	 * @param userinfodao the userinfodao to set
	 */
	public void setUserinfodao(IUserInfoDao userinfodao) {
		this.userinfodao = userinfodao;
	}
}
